package com.huaxinkaiye.lookbigphoto;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;


import com.huaxinkaiye.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.util.ArrayList;

import uk.co.senab.photoview.PhotoView;
/**
 * Created by imac on 15/4/6.
 * 该类用来加载网络图片，能够放大缩小
 */
public class PhotoZoomAdapter extends PagerAdapter {

    private DisplayImageOptions optionsPic;
    private Context context;
    private ArrayList<String> urls;

    public PhotoZoomAdapter(Context context, ArrayList<String> urls) {
        this.context = context;
        this.urls = urls;
        if (optionsPic == null)
            optionsPic = new DisplayImageOptions.Builder()
                    .showImageOnLoading(R.drawable.img_bg_load)
                    .showImageForEmptyUri(R.drawable.img_bg_load)
                    .showImageOnFail(R.drawable.img_bg_load).cacheInMemory(false)
                    .resetViewBeforeLoading(false).cacheOnDisk(true)
                    .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                    .considerExifParams(false).build();
    }


    @Override
    public int getCount() {
        if (urls == null)
            return 0;
        return urls.size();
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        final PhotoView photoView = new PhotoView(context);
        ImageLoader.getInstance().displayImage(urls.get(position), photoView, optionsPic);
        container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        return photoView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

}

